package com.global.emc.spring.exception.handler.messages;

import java.util.Locale;

import org.springframework.context.support.ApplicationObjectSupport;

import com.global.emc.core.exception.IEMCException;
import com.global.emc.core.exception.handler.IEMCExceptionMessagesHandler;

/**
 * 
 * @Description: [使用spring容器解析EMCException类型异常消息]
 * @Author: [Joly]
 * @CreateDate: [2013年12月16日 下午1:33:02]
 * @UpdateUser: [Joly]
 * @UpdateDate: [2013年12月16日 下午1:33:02]
 * @UpdateRemark: [说明本次修改内容]
 * @Version: [v1.0]
 * 
 */
public class EMCExceptionMessagesHandler extends ApplicationObjectSupport implements IEMCExceptionMessagesHandler {
	
	@Override
	public boolean supports(IEMCException emcException) {
		return emcException instanceof IEMCException;
	}

	@Override
	public void resolverMessages(IEMCException emcException,Locale locale) {
		String localizedMessage = null;

		try {
			localizedMessage = super.getApplicationContext().getMessage(emcException.getMessage(), emcException.getArgs(), locale);
			emcException.setLocalizedMessage(localizedMessage);
		} catch (Exception e) {
			this.logger.error("IEMCExceptionResolver error,message:"
					+ (emcException.getMessage())
					+ " in the locale source file is not find");
		}

	}

}
